<template>
  <div>
    <v-dialog v-model="isShowSayForm" persistent max-width="620">
      <v-card>
        <v-form
          class="pa-4"
          ref="sayForm"
          @submit="say"
        >
          <v-text-field
            v-model="sayModel.title"
            label="标题"
            required
          ></v-text-field>
          
          <v-text-field
            v-model="sayModel.subTitle"
            label="副标题"
          ></v-text-field>
          
          <v-textarea
            v-model="sayModel.article"
            label="内容"
            counter
            maxlength="800"
            full-width
            single-line
          ></v-textarea>
          <v-row class="mt-8">
            <v-spacer />
            <v-btn class="accent-4 mr-4" @click="cancelSubmit">取消</v-btn>
            <v-btn class="accent-4 mr-4" type="submit">提交</v-btn>
          </v-row>
        </v-form>
      </v-card>
    </v-dialog>
  </div>
</template>

<script>
export default {
  props: {
    isShowSayForm: {
      type: Boolean,
      default: false,
    },
  },

  data() {
    return {
      sayModel: {
        title: '',
        subTitle: '',
        article: '',
        type: true
      },
    }
  },

  methods: {
    async say() {
      if(this.$axios.defaults.headers.common.Authorization){
        if(this.sayModel.article){
          this.sayModel.wallpaper = '5f6e8ef4483a6e2b0886cb89'
          await this.$axios.$post('says/user', this.sayModel)
          // await this.fetch()
          this.$emit('updateSay', this.sayModel)
          this.sayModel = null
        }else{
          this.$toast.show('请输入内容')
        }
      }else{
        this.$toast.error('请先登录')
      }
    },
    cancelSubmit() {
      this.$refs.sayForm.reset()
      this.$emit('changSayShow', false)
    },
  },
}
</script>

<style></style>
